package cn.com.checne.controller.superManager;

import java.awt.Color;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import cn.com.checne.constants.Constants;
import cn.com.checne.dao.BusinessInfoDao;
import cn.com.checne.dao.CompanyInfoDao;
import cn.com.checne.dao.FriendLinkInfoDao;
import cn.com.checne.dao.GuestBookInfoDao;
import cn.com.checne.dao.IntroduceInfoDao;
import cn.com.checne.dao.JobNewsInfoDao;
import cn.com.checne.dao.LogInfoDao;
import cn.com.checne.dao.NavigateInfoDao;
import cn.com.checne.dao.NewsInfoDao;
import cn.com.checne.dao.PerformanceInfoDao;
import cn.com.checne.dao.WatermarkDao;
import cn.com.checne.model.domain.BusinessInfo;
import cn.com.checne.model.domain.CompanyInfo;
import cn.com.checne.model.domain.FriendLinkInfo;
import cn.com.checne.model.domain.GuestBookInfo;
import cn.com.checne.model.domain.IntroduceInfo;
import cn.com.checne.model.domain.JobNewsInfo;
import cn.com.checne.model.domain.LogInfo;
import cn.com.checne.model.domain.NavigateInfo;
import cn.com.checne.model.domain.NewsInfo;
import cn.com.checne.model.domain.PerformanceInfo;
import cn.com.checne.model.domain.UserInfo;
import cn.com.checne.model.domain.Watermark;
import cn.com.checne.model.dto.BusinessQuery;
import cn.com.checne.model.dto.IntroduceQuery;
import cn.com.checne.model.dto.JobNewsQuery;
import cn.com.checne.model.dto.LogInfoQuery;
import cn.com.checne.model.dto.NewsQuery;
import cn.com.checne.model.dto.PerformanceQuery;
import cn.com.checne.util.FileUtils;
import cn.com.checne.util.PageBean;
import cn.com.checne.util.TimeUtils;
import cn.com.checne.util.WebUtils;
import cn.com.checne.util.XMLUtils;
import cn.com.checne.util.images.ImageContentUtils;
import cn.com.checne.util.watermark.Common;
import cn.com.checne.util.watermark.ImageTool;

@Controller
@RequestMapping(value="/super/sysSetUp")
public class SysSetUpManagerController {
	protected static final Logger logger = Logger.getLogger(SysSetUpManagerController.class);

	@Resource
	private NavigateInfoDao naInfoDao;
	@Resource
	private CompanyInfoDao companyDao;
	@Resource
	private FriendLinkInfoDao linkDao;
	@Resource
	private LogInfoDao logDao;
	@Resource
	private GuestBookInfoDao gbDao ;
	@Resource
	private IntroduceInfoDao introduceDao;
	@Resource
	private BusinessInfoDao businessDao ;
	@Resource
	private PerformanceInfoDao performanceDao ;
	@Resource
	private NewsInfoDao newsDao ;
	@Resource
	private JobNewsInfoDao jobNewsDao ;
	@Resource
	private WatermarkDao wmDao ;
	@Resource
	private List<String> allowedUploadImages ;
	//系统配置管理--首页
	@RequestMapping(value="/index.do")
	public String index(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		return "super/frame/frame_sysSetUp";
	}
	
	//系统配置管理--左侧导航
	@RequestMapping(value="/left.do")
	public String left(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		return "super/sysSetUp/left";
	}
	
	//系统配置管理--列举所有的导航内容
	@RequestMapping(value="/navigate-list.do")
	public ModelAndView navigateList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;
		List<NavigateInfo> navigateList = naInfoDao.getAll(languageId);
		modelMap.put("navigateList", navigateList);
		
		mav.setViewName("super/sysSetUp/navigate-list");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--新增、修改页面
	@RequestMapping(value="/navigate-show.do")
	public ModelAndView navigateShow(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int naId = WebUtils.getRequestParameterAsInt(request, "naId", 0);
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;
		NavigateInfo na = new NavigateInfo();
		na.setLanguageId(languageId);
		String opt = "create" ;
		if(naId > 0){
			na = naInfoDao.getNavigate(naId);
			opt = "update" ;
		}
		modelMap.put("na", na);
		modelMap.put("opt", opt);
		mav.setViewName("super/sysSetUp/navigate-show");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--新增
	@RequestMapping(value="/navigate-create.do")
	public ModelAndView navigateCreate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		NavigateInfo na = new NavigateInfo();
		na.setName(WebUtils.getRequestParameterAsString(request, "name"));
		na.setDesc(WebUtils.getRequestParameterAsString(request, "desc"));
		na.setMark(WebUtils.getRequestParameterAsString(request, "mark"));
		na.setLanguageId(WebUtils.getRequestParameterAsInt(request, "languageId", 1));
		na.setOrder(WebUtils.getRequestParameterAsInt(request, "order",0));
		if(naInfoDao.create(na)){
			message = "导航创建成功!" ;
		}else{
			message = "导航创建失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--修改
	@RequestMapping(value="/navigate-update.do")
	public ModelAndView navigateUpdate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		NavigateInfo na = new NavigateInfo();
		int naId = WebUtils.getRequestParameterAsInt(request, "naId", 0);
		na = naInfoDao.getNavigate(naId);
		na.setName(WebUtils.getRequestParameterAsString(request, "name"));
		na.setDesc(WebUtils.getRequestParameterAsString(request, "desc"));
		na.setMark(WebUtils.getRequestParameterAsString(request, "mark"));
		na.setLanguageId(WebUtils.getRequestParameterAsInt(request, "languageId", 1));
		na.setOrder(WebUtils.getRequestParameterAsInt(request, "order",0));
		if(naInfoDao.update(na)){
			message = "导航修改成功!" ;
		}else{
			message = "导航修改失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--删除
	@RequestMapping(value="/navigate-del.do")
	public ModelAndView navigateDel(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		int naId = WebUtils.getRequestParameterAsInt(request, "naId", 0);
		if(naInfoDao.delete(naId)){
			message = "导航删除成功!" ;
		}else{
			message = "导航删除失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--公司信息--修改页面
	@RequestMapping(value="/company-show.do")
	public ModelAndView companyShow(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int cateId = WebUtils.getRequestParameterAsInt(request, "cateId", 1);
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;

		CompanyInfo company = new CompanyInfo();
		company = companyDao.getCompanyInfo(cateId,languageId);
        String content = company.getContent();
        String replaceContent = ImageContentUtils.setBasePathToImagePath(request,content);
        company.setContent(replaceContent);
        
		if(company.getCompanyId() == 0){ //没有任何信息,需要进行新增
			modelMap.put("opt","create");
		}
		if(cateId == 1){
			modelMap.put("cateName", "联系我们");
		}
		if(cateId == 2){
			modelMap.put("cateName", "关于我们");
		}
		modelMap.put("companyId", company.getCompanyId());
		modelMap.put("content", company.getContent());
		modelMap.put("cateId", cateId);
		modelMap.put("languageId", languageId);
		mav.setViewName("super/sysSetUp/company-show");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--公司信息--修改
	@RequestMapping(value="/company-update.do")
	public ModelAndView companyUpdate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView("common/message");
		String content = WebUtils.getRequestParameterAsString(request, "content") ;
		if(StringUtils.isBlank(content)){
			modelMap.put("message", "内容不能为空!");
			mav.addAllObjects(modelMap);
			return mav ;
		}
		
        content = ImageContentUtils.setBasePathToImagePath(request,content);
		
		int companyId = WebUtils.getRequestParameterAsInt(request, "companyId",0);
		int cateId = WebUtils.getRequestParameterAsInt(request, "cateId", 1);
		int languageId = WebUtils.getRequestParameterAsInt(request, "languageId", 1);
		CompanyInfo company = new CompanyInfo();
		
		String message = "" ;
		//进行修改
		if(companyId > 0){
			company = companyDao.getCompanyInfo(companyId);
			company.setCateId(cateId);
			company.setLanguageId(languageId);
			company.setContent(content);
			if(companyDao.update(company)){
				message = "修改成功!" ;
			}else{
				message = "修改成功!" ;
			}
		}
		//进行新增
		else{
			company.setCateId(cateId);
			company.setLanguageId(languageId);
			company.setContent(content);
			if(companyDao.create(company)){
				message = "添加成功!" ;
			}else{
				message = "添加成功!" ;
			}
		}
		modelMap.put("message", message);
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	
	//系统配置管理--友情链接--列表
	@RequestMapping(value="/link-list.do")
	public ModelAndView linkList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;
		int cateId = WebUtils.getRequestParameterAsInt(request, "cateId", 0);
		List<FriendLinkInfo> linkList = linkDao.getAll(languageId, cateId);
		modelMap.put("linkList", linkList);
		modelMap.put("languageId", languageId);
		modelMap.put("cateId", cateId);
		mav.setViewName("super/sysSetUp/link-list");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	//系统配置管理---友情链接--新增、修改页面
	@RequestMapping(value="/link-show.do")
	public ModelAndView linkShow(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int linkId = WebUtils.getRequestParameterAsInt(request, "linkId", 0);
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;

		FriendLinkInfo link = new FriendLinkInfo();
		link.setLanguageId(languageId);
		String opt = "create" ;
		if(linkId > 0){
			link = linkDao.getFriendLinkInfo(linkId);
			opt = "update" ;
		}
		modelMap.put("link", link);
		modelMap.put("opt", opt);
		mav.setViewName("super/sysSetUp/link-show");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理---友情链接--新增
	@RequestMapping(value="/link-create.do")
	public ModelAndView linkCreate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1 ;
		FriendLinkInfo link = new FriendLinkInfo();
		link.setCateId(WebUtils.getRequestParameterAsInt(request, "cateId",1));
		link.setUrl(WebUtils.getRequestParameterAsString(request, "url"));
		link.setName(WebUtils.getRequestParameterAsString(request, "name"));
		link.setLanguageId(languageId);
		if(linkDao.create(link)){
			message = "创建成功!" ;
		}else{
			message = "创建失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理---友情链接--修改
	@RequestMapping(value="/link-update.do")
	public ModelAndView linkUpdate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		FriendLinkInfo link = new FriendLinkInfo();
		int linkId = WebUtils.getRequestParameterAsInt(request, "linkId", 0);
		link = linkDao.getFriendLinkInfo(linkId);
		link.setCateId(WebUtils.getRequestParameterAsInt(request, "cateId",1));
		link.setUrl(WebUtils.getRequestParameterAsString(request, "url"));
		link.setName(WebUtils.getRequestParameterAsString(request, "name"));
		link.setLanguageId(WebUtils.getRequestParameterAsInt(request, "languageId", 1));
		if(linkDao.update(link)){
			message = "修改成功!" ;
		}else{
			message = "修改失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--友情链接 --删除
	@RequestMapping(value="/link-del.do")
	public ModelAndView linkDel(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		int linkId = WebUtils.getRequestParameterAsInt(request, "linkId", 0);
		if(linkDao.delete(linkId)){
			message = "删除成功!" ;
		}else{
			message = "删除失败!" ;
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//系统配置管理--操作日志--列表
	@RequestMapping(value="/sysLog-list.do")
	public ModelAndView sysLogList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int userId = WebUtils.getRequestParameterAsInt(request, "userId", 0);
		int actionId = WebUtils.getRequestParameterAsInt(request, "actionId", 0);
		int naviId = WebUtils.getRequestParameterAsInt(request, "naviId", 0);
		
		String startTime = WebUtils.getRequestParameterAsString(request, "startTime");
		String endTime = WebUtils.getRequestParameterAsString(request, "endTime");
		
		if(StringUtils.isBlank(startTime)){
			startTime = TimeUtils.getDate(new Date(), "yyyy-MM-dd HH:mm:ss", -7);
		}
		if(StringUtils.isBlank(endTime)){
			endTime = TimeUtils.getDate(new Date(),"yyyy-MM-dd HH:mm:ss", 0);
		}

		LogInfoQuery query = new LogInfoQuery();
		query.setUserId(userId);
		query.setActionId(actionId);
		query.setNaviId(naviId);
		query.setStartTime(startTime);
		query.setEndTime(endTime);
	    int curPage = WebUtils.getRequestParameterAsInt(request, "curPage", 1);
	    PageBean pageBean = new PageBean();
	    pageBean.setCurPage(curPage);
	    List<LogInfo> logList = logDao.getLogListByCondition(query, pageBean.getStart(),pageBean.getRowsPerPage());
	    pageBean.setMaxRowCount(logDao.getLogCountByCondition(query));
	    pageBean.setMaxPage();
	    pageBean.setPageNoList();
	    
		modelMap.put("logList", logList);
		modelMap.put("query", query);
		modelMap.put("pageBean", pageBean);
		mav.setViewName("super/sysSetUp/sysLog-list");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	@RequestMapping(value="/gb-list.do")
	public ModelAndView gbList(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;
		int isShow = WebUtils.getRequestParameterAsInt(request, "isShow",-1);
		int isComment = WebUtils.getRequestParameterAsInt(request, "isComment",-1);
	    int curPage = WebUtils.getRequestParameterAsInt(request, "curPage", 1);
	    PageBean pageBean = new PageBean();
	    pageBean.setCurPage(curPage);
	    List<GuestBookInfo> gbList = gbDao.getGBList(languageId, isShow,isComment, pageBean.getStart(), pageBean.getRowsPerPage());
	    pageBean.setMaxRowCount(gbDao.getGBListCount(languageId, isShow,isComment));
	    pageBean.setMaxPage();
	    pageBean.setPageNoList();
	    
		modelMap.put("gbList", gbList);
		modelMap.put("pageBean", pageBean);
		modelMap.put("isShow", isShow);
		modelMap.put("isComment",isComment);
		mav.setViewName("super/sysSetUp/gb-list");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	@RequestMapping(value="/gb-setIndex.do")
	public ModelAndView gbShowIndex(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		String gbId = WebUtils.getRequestParameterAsString(request, "gbId");
		String flag = WebUtils.getRequestParameterAsString(request, "flag");
		if(StringUtils.isNotBlank(flag) && flag.matches("\\d+")){
			String nds [] = StringUtils.split(gbId, ",") ;
			int gbIds [] = new int[nds.length] ;
			int i = 0 ;
			for(String nd : nds){
				gbIds[i] = Integer.valueOf(nd);
				i ++ ;
			}
			if(gbDao.setShowIndex(Integer.valueOf(flag),gbIds)){
				message = "留言" + (flag.equals("1") ? "设置显示" : "取消显示") + "成功!" ;
			}else{
				message = "留言" + (flag.equals("1") ? "设置显示" : "取消显示") + "失败!" ;
			}
		}
		
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	@RequestMapping(value="/gb-del.do")
	public ModelAndView gbDel(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "留言删除成功!" ;
		String gbId = WebUtils.getRequestParameterAsString(request, "gbId");
		String ids [] = StringUtils.split(gbId, ",") ;
		boolean flag = false ;
		for(String id : ids){
			flag = gbDao.delete(Integer.parseInt(id));
			if(flag == false){
				message = "留言删除失败!" ;
				break ;
			}
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	@RequestMapping(value="/gb-show.do")
	public ModelAndView gbShow(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		int gbId = WebUtils.getRequestParameterAsInt(request, "gbId", 0);
		GuestBookInfo gb = new GuestBookInfo();
		String opt = "create" ;
		if(gbId > 0){
			gb = gbDao.getGuestBookInfo(gbId);
			opt = "update" ;
		}
		modelMap.put("gb", gb);
		modelMap.put("opt", opt);
		mav.setViewName("super/sysSetUp/gb-show");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	@RequestMapping(value="/gb-update.do")
	public ModelAndView gbUpdate(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		GuestBookInfo gb = new GuestBookInfo();
		int gbId = WebUtils.getRequestParameterAsInt(request, "gbId", 0);
		String commentContent = WebUtils.getRequestParameterAsString(request, "commentContent");
		int isShow = WebUtils.getRequestParameterAsInt(request, "isShow", 0);
		
		if(gbId > 0){
			gb = gbDao.getGuestBookInfo(gbId);
			gb.setCommentContent(commentContent);
			UserInfo userInfo = (UserInfo) request.getSession().getAttribute(Constants.SESSIONNAME);
			gb.setCommentUser(userInfo.getId());
			gb.setIsShow(isShow);
			gb.setCommentTime(new Date());
			if(gbDao.update(gb)){
				message = "修改成功!" ;
			}else{
				message = "修改失败!" ;
			}
		}
		modelMap.put("message", message);
		mav.setViewName("common/message");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	
	//图片转化显示页面
	@RequestMapping(value="/changeImageShow.do")
	public ModelAndView changeImageShow(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("super/sysSetUp/changeImage-show");
		mav.addAllObjects(modelMap);
		return mav ;
	}
	@RequestMapping(value="/changeImage.do")
	public ModelAndView changeImage(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		String message = "" ;
		String k = WebUtils.getRequestParameterAsString(request, "k");
		String v = WebUtils.getRequestParameterAsString(request, "v");
		if(StringUtils.isBlank(k)){
			message = "转化失败，起始位置不能为空！" ;
			modelMap.put("message", message);
			mav.setViewName("common/message");
			return mav ;
			
		}
		//公司介绍
		List<IntroduceInfo> inList = introduceDao.getIntroduceListByCondition(new IntroduceQuery(), 0, Integer.MAX_VALUE);
		for(IntroduceInfo i : inList){
			boolean flag = false ;
			if(StringUtils.isNotBlank(i.getContent()) && i.getContent().indexOf(k) > -1){
				i.setContent(i.getContent().replaceAll(k, v));
				flag = true ;
			}
			if(StringUtils.isNotBlank(i.getFirstImage()) && i.getFirstImage().indexOf(k) > -1){
				i.setFirstImage(i.getFirstImage().replaceAll(k, v));
				flag = true ;
			}
			if(flag){
				introduceDao.update(i);
			}
		}
		
		//业务
		List<BusinessInfo> biList = businessDao.getBusinessListByCondition(new BusinessQuery(), 0, Integer.MAX_VALUE);
		for(BusinessInfo i : biList){
			boolean flag = false ;
			if(StringUtils.isNotBlank(i.getContent()) && i.getContent().indexOf(k) > -1){
				i.setContent(i.getContent().replaceAll(k, v));
				flag = true ;
			}
			if(StringUtils.isNotBlank(i.getFirstImage()) && i.getFirstImage().indexOf(k) > -1){
				i.setFirstImage(i.getFirstImage().replaceAll(k, v));
				flag = true ;
			}
			if(flag){
				businessDao.update(i);
			}
		}
		
		//业绩
		List<PerformanceInfo> perList = performanceDao.getPerformanceListByCondition(new PerformanceQuery(), 0, Integer.MAX_VALUE);
		for(PerformanceInfo i : perList){
			boolean flag = false ;
			if(StringUtils.isNotBlank(i.getContent()) && i.getContent().indexOf(k) > -1){
				i.setContent(i.getContent().replaceAll(k, v));
				flag = true ;
			}
			if(StringUtils.isNotBlank(i.getFirstImage()) && i.getFirstImage().indexOf(k) > -1){
				i.setFirstImage(i.getFirstImage().replaceAll(k, v));
				flag = true ;
			}
			if(flag){
				performanceDao.update(i);
			}
		}
		
		//新闻
		List<NewsInfo> newsList = newsDao.getNewsListByCondition(new NewsQuery(), 0, Integer.MAX_VALUE);
		for(NewsInfo i : newsList){
			boolean flag = false ;
			if(StringUtils.isNotBlank(i.getContent()) && i.getContent().indexOf(k) > -1){
				i.setContent(i.getContent().replaceAll(k, v));
				flag = true ;
			}
			if(StringUtils.isNotBlank(i.getFirstImage()) && i.getFirstImage().indexOf(k) > -1){
				i.setFirstImage(i.getFirstImage().replaceAll(k, v));
				flag = true ;
			}
			if(flag){
				newsDao.update(i);
			}
		}
		
		//JOB新闻
		List<JobNewsInfo> jobNewsList = jobNewsDao.getJobNewsListByCondition(new JobNewsQuery(), 0, Integer.MAX_VALUE);
		for(JobNewsInfo i : jobNewsList){
			boolean flag = false ;
			if(StringUtils.isNotBlank(i.getContent()) && i.getContent().indexOf(k) > -1){
				i.setContent(i.getContent().replaceAll(k, v));
				flag = true ;
			}
			if(StringUtils.isNotBlank(i.getFirstImage()) && i.getFirstImage().indexOf(k) > -1){
				i.setFirstImage(i.getFirstImage().replaceAll(k, v));
				flag = true ;
			}
			if(flag){
				jobNewsDao.update(i);
			}
		}
		
		 //重置滚动图片
        NewsQuery query = new NewsQuery();
        query.setLanguageId(1);
        //必须是公司新闻动态类别
        query.setCateId(1);
        XMLUtils.buildXML(newsDao.getNewsImagesListByCondition(query, 0, 6), "cn");

        query.setLanguageId(2);
        //必须是公司新闻动态类别
        query.setCateId(5);
        XMLUtils.buildXML(newsDao.getNewsImagesListByCondition(query, 0, 6), "en");
        
		message = "转化成功<br/>转化前位置=" + k + " <br/>转化后位置=" + v  ;
		modelMap.put("message", message);
		mav.setViewName("common/message");
		return mav ;
	}
	
	@RequestMapping(value="/watermark.do")
	public ModelAndView watermark(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("super/sysSetUp/watermark-show");
		//字体
		String font [] = Common.getAvailableFontFamilyNames();
		
		Watermark wm = new Watermark();
		if(request.getMethod().equalsIgnoreCase("get")){
			int languageId = (String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE) != null ? Integer.parseInt((String)request.getSession().getAttribute(Constants.SESSIONLANGUAGE)) : 1;
			wm = wmDao.getWatermarkByLgId(languageId);
		}
		
		if(request.getMethod().equalsIgnoreCase("post")){
			WatermarkManager wmManager = new WatermarkManager();
			//水印开关
			int switchStatus = WebUtils.getRequestParameterAsInt(request, "switchStatus", 0);
			//语种
			int languageId = WebUtils.getRequestParameterAsInt(request, "languageId", 1);
			//字体
			String fontName = WebUtils.getRequestParameterAsString(request, "font");
			//字体大小
			int fontSize = WebUtils.getRequestParameterAsInt(request, "fontsize", 50);
			//字体样式
			int fontstyleIndex = WebUtils.getRequestParameterAsInt(request, "fontstyle", 0);
			//字体颜色
			int fontcolorIndex = WebUtils.getRequestParameterAsInt(request, "fontcolor",0);
			//缩放比例 default 不缩放
			int scaleIndex = WebUtils.getRequestParameterAsInt(request, "scale",0);
			//水印位置
			int towardIndex = WebUtils.getRequestParameterAsInt(request, "toward",0);
			//水印内容
			String mark = WebUtils.getRequestParameterAsString(request, "mark");
			//水印透明度
			float alpha = WebUtils.getRequestParameterAsFloat(request, "alpha", 0.5f);
			
			//水印的颜色
			Color fontColor = wmManager.colors[fontcolorIndex];
			//水印位置
			int toward = towardIndex;
			//添加水印的字体
			Font f = new Font(fontName, wmManager.fontstyles[fontstyleIndex], (int)(fontSize*wmManager.imgScales[scaleIndex]));
			//放缩比例
			float scale = wmManager.imgScales[scaleIndex];
			
			// 图片上传
			@SuppressWarnings("deprecation")
			String basePath = request.getRealPath("/") + "/";
			String srcImage = null ;
			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
			MultipartFile multipartFile = multipartRequest.getFile("image");
			String originalFilename = multipartFile.getOriginalFilename();
			if(StringUtils.isNotBlank(originalFilename)){
				if (!isAllowed(originalFilename)) {
					modelMap.put("message", "上传文件类型不符合,必须是以下几种<br/>"
							+ this.allowedUploadImages.toString());
					mav.addAllObjects(modelMap);
					return mav ;
				}
				String fileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss")
						+ "." + FilenameUtils.getExtension(originalFilename);
				String relativePath = "userfiles/upload/watermark/"
						+ DateFormatUtils.format(new Date(), "yyyy-MM-dd").replaceAll(
								"-", "/") + "/";
				FileUtils.mkdirs(basePath + relativePath);
				multipartFile.transferTo(new File(basePath + relativePath + fileName));
				srcImage = relativePath + fileName;
				
				String destImageName = fileName ;
				if(switchStatus == 1){
					BufferedImage buffImg = ImageTool.watermark(basePath + srcImage, f, fontColor,toward, mark, alpha, scale);
					destImageName = fileName.substring(0,fileName.lastIndexOf(".")) + "_watermark." + FilenameUtils.getExtension(fileName) ;
					ImageIO.write(buffImg, FilenameUtils.getExtension(originalFilename), new File(basePath + relativePath + destImageName));
				}
				wm = wmDao.getWatermarkByLgId(languageId);
				wm.setSwitchStatus(switchStatus);
				wm.setLg(languageId);
				wm.setFont(fontName);
				wm.setFontColor(fontcolorIndex);
				wm.setFontSize(fontSize);
				wm.setFontStyle(fontstyleIndex);
				wm.setToward(towardIndex);
				wm.setScale(scaleIndex);
				wm.setAlpha(alpha);
				wm.setMark(mark);
				wmDao.update(wm);
				
				modelMap.addAttribute("watermarkPath", relativePath + destImageName + "?t=" + System.currentTimeMillis());
				mav.addAllObjects(modelMap);
				mav.setViewName("super/sysSetUp/watermark-preview");
				return mav ;
			}else{
				modelMap.put("message", "上传图片不能为空!");
				mav.setViewName("common/message");
				return mav ;
			}
		}
		modelMap.addAttribute("font", font);
		modelMap.addAttribute("wm", wm);
		mav.addAllObjects(modelMap);
		return mav ;
	}
	public boolean isAllowed(String fileName) {
		for (String suffix : this.allowedUploadImages) {
			if (StringUtils.equalsIgnoreCase(suffix,
					FilenameUtils.getExtension(fileName))) {
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		String a = "a.2.4.f";
		System.out.println(a.substring(a.lastIndexOf(".") + 1));
		System.out.println(a.substring(0,a.lastIndexOf(".")));
	}
}